#!/afs/psi.ch/user/b/braun_p/user/epd/bin/python

import sys
import os
from pyE17 import io
from pyE17 import utils as U
import numpy as np
from core_object_modes import ortho
usage = """\
Usage:
%s reconstruction_file.h5 [dump_file]

Shows on screen a summary plot of a ptycho reconstruction.
If dump_file is specified, the plot is dumped instead (in a format
that depends on the extension - typically .png, .jpg, .pdf or .svg).
""" % sys.argv[0]

name,ext = os.path.splitext(os.path.basename(sys.argv[1]))
print sys.argv[1]
h5 = io.h5read(sys.argv[1])
probes = h5['probe']
psize = probes.shape
objects = h5['object']
osize = objects.shape
total_probe = np.zeros_like((probes[0,0,:,:]))
for oindex in range(psize[0]):
    for pindex in range(psize[1]): 
        U.imsave(probes[oindex,pindex,:,:],'%s_probe_%d_%d.%s' % (name,oindex,pindex,sys.argv[2]))
        total_probe += probes[oindex,pindex,:,:]
for oindex in range(osize[0]):
    for pindex in range(osize[1]): 
        U.imsave(objects[oindex,pindex,:,:],'%s_object_%d_%d.%s' % (name,oindex,pindex,sys.argv[2]))
U.imsave(total_probe,'%s_total_probe.%s' % (name,sys.argv[2]))
sys.exit(0)
